#!/bin/sh
# NOTES: this shell should be run on master!
des_host='10.232.*.*'
svnroot_arr='/opt/svnroot /opt/svnroot/wl'
notallowed="test2"
logdir=~/log
mkdir $logdir
export LANG=en_US.UTF-8
#for repos in tianyun_doc  
rm $logdir/checkerr.log
for svnroot in $svnroot_arr
do
for repos in `ls $svnroot`
do
	if [ ! -d $svnroot/$repos/db ];then
		continue
	fi
	if [ ! -d $svnroot/$repos/conf ];then
		continue
	fi
	echo $repos | grep -E "$notallowed"
	if [ $? == 0 ];then
		continue
	fi
	srcrev=`svnlook youngest $svnroot/$repos`
	revend=`ssh ads@$des_host "svnlook youngest $svnroot/$repos"`
	if [ -z $revend ];then
		revend=0
	fi
	high=$(($srcrev-$revend))
	if [ $high -gt 50 ];then
		echo "$svnroot/$repos is too old! $srcrev:$revend" |tee -a $logdir/checkerr.log
	fi
	revstart=$(($revend-3))
	if [ $revstart -lt 0 ];then
		revstart=0
		echo "$repos is empty!"
		continue
	fi
	src_sha=`svn log -v -r$revstart:$revend file://$svnroot/$repos`
	des_sha=`ssh ads@$des_host "export LANG=en_US.UTF-8;svn log -v -r$revstart:$revend file://$svnroot/$repos"`
	des_size=`echo $des_sha|wc -c`
	src_size=`echo $src_sha|wc -c`
	if [ ! x"$des_size" == x"$src_size" ];then
		echo "Error: $svnroot/$repos mismatch" |tee -a $logdir/checkerr.log
		echo "$des_size $src_size" |tee -a $logdir/checkerr.log
echo $src_sha > my.log
echo $des_sha > your.log
	fi
done
done
if [ -s $logdir/checkerr.log ];then
	cat $logdir/checkerr.log | mail -s "found error on mirror `date +%Y%m%d`" "xuejiang@taobao.com,baicheng@taobao.com"
fi
